package org.dromara.system.kernel;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.redis.utils.CacheUtils;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.system.constants.OrderConstants;
import org.dromara.system.domain.PayGroupAccount;
import org.dromara.system.mapper.PayGroupAccountMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PayGroupAccountKernel {


    private final PayGroupAccountMapper payGroupAccountMapper;

    /**
     * 修改轮询组收款账号
     *
     * @param account 轮询组收款账号
     * @return 是否修改成功
     */
    public Boolean updateGroupAccount(PayGroupAccount account, Wrapper<PayGroupAccount> wrapper) {
        List<PayGroupAccount> list = payGroupAccountMapper.selectList(wrapper);
        for (PayGroupAccount groupAccount : list) {
            RedisUtils.deleteObject(OrderConstants.pay_group_account + groupAccount.getId());
        }
        return payGroupAccountMapper.update(account, wrapper) > 0;
    }
}
